package com.raising.modules.sys.entity;

import com.raising.framework.entity.BaseEntity;
import com.raising.modules.sys.entity.enums.DataScopeEnum;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * 权限表
 * 
 * @author gaoy
 */
public class Role extends BaseEntity<Role> {

	private static final long serialVersionUID = 1L;
	/** 角色标识 */
	private String role;
	/** 角色名称 */
	private String name;
	/** 机构标识 */
	private String orgId;
	/** 机构名称 */
	private String orgNm;
	/** 数据范围 */
	private DataScopeEnum dataScope = DataScopeEnum.self;
	/** 拥有资源 */
	private List<String> resourceIds;
	/** 拥有资源 */
	private String resourceIdsStr;
	/** 是否可用 */
	private Boolean available = Boolean.TRUE;
	/** 站点URL */
	private String siteUrl;
	/** 默认首页路径 */
	private String indexUrl;
	/** 排序 */
	private int sort=0;

	public Role() {
		super();
	}

	public Role(String id) {
		super(id);
	}

	public Role(String role, String name, Boolean available) {
		super();
		this.role = role;
		this.name = name;
		this.available = available;
	}

	public String getRole() {
		return role;
	}

	public void setRole(String role) {
		this.role = role;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public DataScopeEnum getDataScope() {
		return dataScope;
	}

	public void setDataScope(DataScopeEnum dataScope) {
		this.dataScope = dataScope;
	}

	@Override
	public String getOrgId() {
		return orgId;
	}

	@Override
	public void setOrgId(String orgId) {
		this.orgId = orgId;
	}

	@Override
	public String getOrgNm() {
		return orgNm;
	}

	@Override
	public void setOrgNm(String orgNm) {
		this.orgNm = orgNm;
	}

	public List<String> getResourceIds() {
		if (resourceIds == null) {
			resourceIds = new ArrayList<String>();
		}
		return resourceIds;
	}

	public void setResourceIds(List<String> resourceIds) {
		this.resourceIds = resourceIds;
	}

	public String getResourceIdsStr() {
		if (CollectionUtils.isEmpty(resourceIds)) {
			return "";
		}
		StringBuilder s = new StringBuilder();
		for (String resourceId : resourceIds) {
			s.append(resourceId);
			s.append(",");
		}
		return s.toString();
	}

	public void setResourceIdsStr(String resourceIdsStr) {
		if (StringUtils.isEmpty(resourceIdsStr)) {
			return;
		}
		String[] resourceIdStrs = resourceIdsStr.split(",");
		for (String resourceIdStr : resourceIdStrs) {
			if (StringUtils.isEmpty(resourceIdStr)) {
				continue;
			}
			getResourceIds().add(resourceIdStr);
		}
	}

	public Boolean getAvailable() {
		return available;
	}

	public void setAvailable(Boolean available) {
		this.available = available;
	}

	public String getIndexUrl() {
		return indexUrl;
	}

	public void setIndexUrl(String indexUrl) {
		this.indexUrl = indexUrl;
	}

	public String getSiteUrl() {
		return siteUrl;
	}

	public void setSiteUrl(String siteUrl) {
		this.siteUrl = siteUrl;
	}

	public int getSort() {
		return sort;
	}

	public void setSort(int sort) {
		this.sort = sort;
	}
}

